package server;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import javax.swing.JFrame;

public class Server {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				ServerFrame mainFrame = new ServerFrame();
				mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				mainFrame.setVisible(true);
				mainFrame.setMinimumSize(new Dimension(200,150));
			}
		});/*
			Integer portNumber;
		Integer broadCastPortNumber;
		for (String a : args) {
			System.out.println(a);
		}

		if (args.length == 0) {
			portNumber = 3001;
		} else {
			portNumber = Integer.getInteger(args[0]);
		}

		SmashTrisManager manager = new SmashTrisManager();
		broadCastPortNumber = portNumber + 1;
		// TODO Auto-generated method stub
		ServerSocket serverSocket = null;
		ServerSocket serverBroadcastSocket = null;
		try {
			serverSocket = new ServerSocket(portNumber);
			serverBroadcastSocket = new ServerSocket(broadCastPortNumber);
		} catch (IOException e) {
			System.out.println("Could not listen on port" + portNumber);
			System.exit(-1);
		}

		while (true) {
			Socket clientSocket = null;
			Socket broadcastClientSocket = null;
			try {
				clientSocket = serverSocket.accept();
				broadcastClientSocket = serverBroadcastSocket.accept();
				System.out.println("Utworzono połączenie");
				// manager.addSocketToBroadCast(broadcastClientSocket);

				ObjectOutputStream out = new ObjectOutputStream(
						new BufferedOutputStream(
								broadcastClientSocket.getOutputStream()));
				out.flush();

				Connection connection = new Connection(clientSocket, out,
						manager);

			} catch (IOException e) {
				System.out.println("Accept failed: " + portNumber);
				System.exit(-1);
			}
		}*/

	}


}
